﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ReworkManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ReworkManagement.ReworkDataVMs
{
    public partial class ReworkDataListVM : BasePagedListVM<ReworkData_View, ReworkDataSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ReworkData_View>> InitGridHeader()
        {
            return new List<GridColumn<ReworkData_View>>{
                
                this.MakeGridHeader(x => x.ReworkData_WoId).SetTitle(@Localizer["Page.工单号"].Value),
                this.MakeGridHeader(x => x.ReworkData_WoCode).SetTitle(@Localizer["Page.工单编码"].Value),
                this.MakeGridHeader(x => x.ReworkData_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ReworkData_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ReworkData_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.ReworkData_ReType).SetTitle(@Localizer["Page.返工类型"].Value),
                this.MakeGridHeader(x => x.ReworkData_ReTypeDesc).SetTitle(@Localizer["Page.返工描述"].Value),
                this.MakeGridHeader(x => x.ReworkData_ReasonName).SetTitle(@Localizer["Page.原因名称"].Value),
                this.MakeGridHeader(x => x.ReworkData_ReasonCode).SetTitle(@Localizer["Page.原因编码"].Value),
                this.MakeGridHeader(x => x.ReworkData_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.ReworkData_Operation).SetTitle(@Localizer["Page.操作员"].Value),
                this.MakeGridHeader(x => x.ReworkData_Data).SetTitle(@Localizer["Page.返工数据"].Value),
                this.MakeGridHeader(x => x.ReworkData_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ReworkData_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ReworkData_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ReworkData_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ReworkData_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ReworkData_View> GetSearchQuery()
        {
            var query = DC.Set<ReworkData>()
                
                .CheckEqual(Searcher.WoId, x=>x.WoId)
                .CheckContain(Searcher.WoCode, x=>x.WoCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.ReTypeId, x=>x.ReTypeId)
                .CheckContain(Searcher.ReTypeDesc, x=>x.ReTypeDesc)
                .CheckContain(Searcher.ReasonName, x=>x.ReasonName)
                .CheckContain(Searcher.ReasonCode, x=>x.ReasonCode)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckContain(Searcher.Operation, x=>x.Operation)
                .CheckContain(Searcher.Data, x=>x.Data)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ReworkData_View
                {
				    ID = x.ID,
                    
                    ReworkData_WoId = x.WoId,
                    ReworkData_WoCode = x.WoCode,
                    ReworkData_ProductId = x.ProductId,
                    ReworkData_ProductName = x.ProductName,
                    ReworkData_Sn = x.Sn,
                    ReworkData_ReType = x.ReType.TenantCode,
                    ReworkData_ReTypeDesc = x.ReTypeDesc,
                    ReworkData_ReasonName = x.ReasonName,
                    ReworkData_ReasonCode = x.ReasonCode,
                    ReworkData_Remark = x.Remark,
                    ReworkData_Operation = x.Operation,
                    ReworkData_Data = x.Data,
                    ReworkData_CreateTime = x.CreateTime,
                    ReworkData_UpdateTime = x.UpdateTime,
                    ReworkData_CreateBy = x.CreateBy,
                    ReworkData_UpdateBy = x.UpdateBy,
                    ReworkData_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ReworkData_View: ReworkData
    {
        
        public long? ReworkData_WoId { get; set; }
        public string ReworkData_WoCode { get; set; }
        public long? ReworkData_ProductId { get; set; }
        public string ReworkData_ProductName { get; set; }
        public string ReworkData_Sn { get; set; }
        public string ReworkData_ReType { get; set; }
        public string ReworkData_ReTypeDesc { get; set; }
        public string ReworkData_ReasonName { get; set; }
        public string ReworkData_ReasonCode { get; set; }
        public string ReworkData_Remark { get; set; }
        public string ReworkData_Operation { get; set; }
        public string ReworkData_Data { get; set; }
        public DateTime? ReworkData_CreateTime { get; set; }
        public DateTime? ReworkData_UpdateTime { get; set; }
        public string ReworkData_CreateBy { get; set; }
        public string ReworkData_UpdateBy { get; set; }
        public bool ReworkData_IsValid { get; set; }

    }

}